package com.huqu.beans.sessionWeb;

import java.io.Serializable;
import java.util.Locale;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import com.huqu.utils.ApplicationConstant;
import com.huqu.utils.ApplicationHelper;

@ManagedBean(name="sessionWeb")
@SessionScoped
public class SessionWeb implements Serializable {
	private static final long serialVersionUID = -1616514499850063685L;

	public Locale locale = FacesContext.getCurrentInstance().getViewRoot()
			.getLocale();
	
	public String vLang="VN";
	public String keysearch="";
	
	@PostConstruct
	public void init(){
		try {
			System.out.println("====== SessionBean =======");
			System.out.println("---- Locale= "+locale);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	/*xét lại ngộn ngữ*/
	public void setLanguage(String strlocale){
		try {
			if(strlocale.trim().equals("en")||strlocale.trim().equals("EN")){
				locale=Locale.US;
				FacesContext.getCurrentInstance()
    			.getViewRoot().setLocale(locale);
			}else{
				locale=new Locale("vi", "VN");
				FacesContext.getCurrentInstance()
    			.getViewRoot().setLocale(locale);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	// action khi click vào btn search trên header
	public void clickSearchHeader(){
		try {
			ApplicationHelper.setSession(ApplicationConstant.KEY_SEARCH, keysearch);
			keysearch="";
			ApplicationHelper.gotoPage("http://localhost:8081/huongnghiep/vn/tim-kiem/");
			/*if(keysearch.trim().length()>0){
				ApplicationConstant
			}*/
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	public Locale getLocale() {
		return locale;
	}
	public void setLocale(Locale locale) {
		this.locale = locale;
	}
	
	public String getvLang() {
		if(locale.equals(Locale.US)){
			vLang="EN";
		}else if(locale.equals(new Locale("vi", "VN"))){
			vLang="VN";
		}else{
			vLang="VN";
		}
		return vLang;
	}
	
	public void setvLang(String vLang) {
		this.vLang = vLang;
	}

	public String getKeysearch() {
		return keysearch;
	}
	public void setKeysearch(String keysearch) {
		this.keysearch = keysearch;
	}
	
	
}
